package com.biallen.datastructure.stack;

public class ArrayStack {


    private int maxSize;

    private int top =  -1;

    private int[] data;

    public ArrayStack(int maxSize) {
        this.maxSize = maxSize;
        data= new int[maxSize];
    }

    public  boolean isFull(){
        return top == maxSize-1;
    }

    public  boolean isEmpty(){
        return  top == -1;
    }

    /**
     * 获取栈顶的值
     * @return
     */
    public  int peek(){
        return  data[top];
    }
    /**
     * 入栈
     * @param value
     */
    public  void  push(int value){

        if(isFull()){
            System.out.println("栈已满");
            return;
        }
        top++;
        data[top]= value;
    }

    /**
     * 出栈
     * @return
     */
    public  int pop (){
        if(isEmpty()) {
            throw  new RuntimeException(" 栈空 没数据!");
        }
        int datum = data[top];
        top --;
        return datum;
    }

    public  int culcate(int  num1 ,int num2,int ch){
        int res=0;
        switch (ch){
            case  '*':
                res= num1 * num2;
                break;
            case '/':
                res =num2/num1;
                break;
            case '+':
                res =  num1+num2;
                break;
            case '-':
                res= num2-num1;
                break;
            default:
                break;
        }
        return  res;
    }

    public  boolean isOper(int ch){

        return  ch =='+' || ch =='-'|| ch=='*' || ch =='/';
    }

    public  int priority(int oper){

        if( oper == '*' || oper == '/'){
            return  1;
        }else  if( oper  == '+' || oper == '-'){
            return 0;
        }else {
            return   -1;
        }
    }

    public  String  transforExpress(String expression){
         return null;
    }


}
